finding the nth term if sum